package com.ny.mapper;

import com.ny.entity.Device;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeviceMapper {
    
    /**
     * 查询所有设备信息
     * @return 设备列表
     */
    @Select("SELECT * FROM device")
    @Results({
        @Result(property = "deviceId", column = "device_id"),
        @Result(property = "deviceSn", column = "device_sn"),
        @Result(property = "deviceName", column = "device_name"),
        @Result(property = "deviceType", column = "device_type"),
        @Result(property = "roomId", column = "room_id"),
        @Result(property = "createdTime", column = "created_time")
    })
    List<Device> findAllDevices();
    
    /**
     * 根据设备名称查询设备信息
     * @param deviceName 设备名称
     * @return 设备列表
     */
    @Select("SELECT * FROM device WHERE device_name LIKE CONCAT('%', #{deviceName}, '%')")
    @Results({
        @Result(property = "deviceId", column = "device_id"),
        @Result(property = "deviceSn", column = "device_sn"),
        @Result(property = "deviceName", column = "device_name"),
        @Result(property = "deviceType", column = "device_type"),
        @Result(property = "roomId", column = "room_id"),
        @Result(property = "createdTime", column = "created_time")
    })
    List<Device> findDevicesByName(@Param("deviceName") String deviceName);
    
    /**
     * 根据设备ID删除设备信息
     * @param deviceId 设备ID
     * @return 删除结果影响的行数
     */
    @Delete("DELETE FROM device WHERE device_id = #{deviceId}")
    int deleteDeviceById(@Param("deviceId") int deviceId);
}